package org.servlet;

import com.google.gson.Gson;
import org.domain.Account;
import org.service.CartService;
import org.service.SearchAjaxService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class AjaxUpdateCartServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        Account account = (Account)session.getAttribute("account");
        String name = request.getParameter("productIdAjax");
        String uid = account.getUsername();

        //向server层调用相应的业务
        CartService cartService = new CartService();
        int q = cartService.getQuantityById(name,uid);
        //返回结果
        String json = String.valueOf(q);

        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().write(json);
    }
}
